package xhwl.insurance.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;

import java.util.ArrayList;

import xhwl.android.common.log.XHLog;
import xhwl.android.common.util.SPUtil;
import xhwl.android.common.util.StringUtil;
import xhwl.insurance.BaseActivity;
import xhwl.insurance.R;
import xhwl.insurance.adapter.UserGuideAdapter;
import xhwl.insurance.http.api.UserGuideApi;
import xhwl.insurance.http.bean.resp.UserGuideListResp;
import xhwl.retrofitrx.HttpException;
import xhwl.retrofitrx.HttpManager;
import xhwl.retrofitrx.OnNextListener;

/**
 * Created by Administrator on 2017/8/24.
 * 用户指南
 */

public class UserGuideActivity extends BaseActivity  {


    private ListView mListView;
    ArrayList<UserGuideListResp> mList = new ArrayList<UserGuideListResp>();
    private UserGuideAdapter adapter;
    private LinearLayout emptyView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_guide_activity);
    }
    @Override
    public void initViews() {
        initTitleViews();
        mListView = (ListView)findViewById(R.id.lv_guide_listview);
        emptyView = (LinearLayout)findViewById(R.id.emptyView);

    }

    @Override
    public void initListener() {
    }
    @Override
    protected void setUpTitleView() {
        titleTextView.setText("用户指南");
    }


    public void getLoad(int page ) {
        String member_id = SPUtil.getPersonInfoSp().getString(SPUtil.SPPersonInfo.MEMBER_ID,null);
        if (StringUtil.isEmpty(member_id)) {
            return;
        }
        UserGuideApi api = new UserGuideApi(member_id,page);
        HttpManager.getInstance().dealHttp(this,api,new OnNextListener<ArrayList<UserGuideListResp>>(){
            @Override
            public void onNext(ArrayList<UserGuideListResp> resp) {
                try {
                    if (null != resp && 0 < resp.size()){
                        mList.addAll(resp);
                        adapter.notifyDataSetChanged();
                    }else {
                        emptyView.setVisibility(View.VISIBLE);
                    }
                } catch (Exception e) {
                    // TODO: handle exception
                    XHLog.e(e.getMessage());

                }
            }

            @Override
            public void onError(HttpException ex) {
                super.onError(ex);

            }
        });
    }



    @Override
    protected void processOper() {
        adapter = new UserGuideAdapter(mContext, mList);
        mListView.setAdapter(adapter);
    }

    @Override
    public void loadData() {
        getLoad(1);
    }
}
